package com.company;

import java.util.Scanner;

/**
 * @author jrue
 * @version 1.0
 * @date 2020/3/17 19:21
 */
public class Main03 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int w = sc.nextInt();
        int[] ws = new int[n + 1];

        for (int i = 1; i < ws.length; i++) {
            ws[i] = sc.nextInt();
        }

        int[] vs = new int[n + 1];

        for (int i = 1; i < vs.length; i++) {
            vs[i] = sc.nextInt();
        }

        int[][] dp = new int[n + 1][w + 1];

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= w; j++) {
                if (j >= ws[i]) {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - ws[i]] + vs[i]);
                }
            }
        }

        System.out.println(dp[n][w]);
    }
}
